package com.zero.common;

public class SortClass {
    static void quickSort(int[] arr){
        for(int i=0; i<arr.length; i++){

        }
    }

    static void insertSort(int[] arr){
        for(int i=1; i<arr.length; i++){
            int data = arr[i];
            int j=i-1;
            for(; j>=0; j--){
                if(arr[j] > data){
                    arr[j+1] = arr[j];
                }else{
                    break;
                }
            }
            arr[j+1] = data;
        }
    }

    static void shellSort(int[] arr){
        int n = arr.length;
        for(int k=n/2; k>=1; ){
            for(int p=0; p<k; p++){
                for(int i=k+p; i<n; ){
                    int data = arr[i];
                    int j =  i-k;
                    for(; j>=p; ){
                        if(arr[j] > data){
                            arr[j+k] = arr[j];
                        }else{
                            break;
                        }
                        j=j-k;
                    }
                    arr[j+k] = data;
                    i=i+k;
                }
            }
            k=k/2;
        }
    }

    static void mergeSort(int[] arr, int left, int right){
        if(left < right){
            int mid = (left + right) / 2;
            mergeSort(arr, left, mid);
            mergeSort(arr, mid + 1, right);
        }
    }

    public static void main(String[] args) {
        int[] arr = {3, 4, 7, 2, 1, 0};
//        shellSort(arr);
//        insertSort(arr);
        mergeSort(arr, 0, arr.length-1);
        for(int i=0; i<arr.length; i++){
            System.out.print(arr[i] + " ");
        }
    }
}
